package com.thd.springboottest.security.service;


import com.thd.springboottest.security.entity.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.stereotype.Component;

/**
 * com.thd.springboottest.security.service.MyUserDetailsService
 *
 * @author: wanglei62
 * @DATE: 2022/6/21 17:50
 **/
@Component
public class MyUserDetailsService implements UserDetailsService {
    @Autowired
    private UserService userService;
    @Autowired
    private PasswordEncoder passwordEncoder;
    @Override
    public UserDetails loadUserByUsername(String userName) throws UsernameNotFoundException {
        User u = userService.loadUserByAccount(userName);
        return u;


        // 下面代码是练习时候使用的
//        System.out.println("用户登录:"+ userName);
//        return new org.springframework.security.core.userdetails.User(userName,passwordEncoder.encode("123456"), AuthorityUtils.commaSeparatedStringToAuthorityList("admin"));
    }
}
